<template>
  <div>
    <el-button type="primary" @click="handleAdd">新增用户</el-button>
    <el-table :data="tableData" border>
      <el-table-column prop="name" label="姓名" />
      <el-table-column prop="email" label="邮箱" />
      <el-table-column label="操作">
        <template #default="scope">
          <el-button size="small" @click="handleEdit(scope.row)"
            >编辑</el-button
          >
          <el-button type="danger" size="small" @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      v-model:current-page="currentPage"
      :page-size="pageSize"
      :total="total"
      @current-change="fetchData"
    />
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { getUsers } from "@/api";

const tableData = ref([]);
const currentPage = ref(1);
const pageSize = 10;
const total = ref(0);

const fetchData = async () => {
  const res = await getUsers({ page: currentPage.value, size: pageSize });
  tableData.value = res.data;
  total.value = res.total;
};

onMounted(fetchData);
</script>
